package com.cn.web.theme.service.impl;

import com.alibaba.fastjson.JSON;
import com.cn.theme.ThemeDO;
import com.cn.theme.ThemeVO;
import com.cn.web.theme.mapper.IThemeMapper;
import com.cn.web.theme.service.ThemeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * description: ThemeService <br>
 * date: 23.1.5 11:33 <br>
 * author: cn_yaojin <br>
 * version: 1.0 <br>
 */
@Service
@Slf4j
public class ThemeServiceImpl implements ThemeService {

    @Autowired
    private IThemeMapper themeMapper;

    @Override
    public ThemeVO find() {
        ThemeDO data = this.themeMapper.selectById(1);
        ThemeVO themeVo = null;
        if (StringUtils.isNotEmpty(data.getContent())) {
            themeVo = JSON.parseObject(data.getContent(), ThemeVO.class);
        } else {
            themeVo = new ThemeVO();
        }
        themeVo.setId(data.getId());
        return themeVo;
    }

    @Override
    public void edit(ThemeVO themeVo) {
        ThemeDO data = this.themeMapper.selectById(themeVo.getId());
        themeVo.setId(null);
        data.setContent(JSON.toJSONString(themeVo));
        this.themeMapper.updateById(data);
    }

}
